<template>
  <el-dialog title="不合理处方" :close-on-click-modal="false" :visible.sync="visible" fullscreen center append-to-body>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>

    <el-form :model="dataForm" label-width="100px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="处方单号">
            <el-input v-model="dataForm.presBillId" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="处方日期">
            <el-input v-model="dataForm.presBillId" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="姓名">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="性别">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="年龄">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="门诊号">
            <el-input v-model="dataForm.presBillId" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="电话">
            <el-input v-model="dataForm.presBillId" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="临床(初步)诊断">
            <el-input type="textarea" v-model="dataForm.presBillId" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>


      <el-divider content-position="left">处方信息</el-divider>

      <div class="avue-crud" style="margin-bottom: 20px;">
        <el-table :data="dataList" border>
          <el-table-column prop="medicineName" header-align="center" align="center" label="药品名称"></el-table-column>
          <el-table-column prop="usages" header-align="center" align="center" label="用法"></el-table-column>
          <el-table-column prop="usageLocation" header-align="center" align="center" label="用药部位"></el-table-column>
          <el-table-column prop="metering" header-align="center" align="center" label="单次剂量"></el-table-column>
          <el-table-column prop="frequency" header-align="center" align="center" label="频次"></el-table-column>
          <el-table-column prop="money" header-align="center" align="center" label="金额"></el-table-column>
        </el-table>
      </div>
      <el-row>
        <el-col :span="6">
          <el-form-item label="药费">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="医师">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="调配医师">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="审核医师">
            <el-input v-model="dataForm.presonName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-divider content-position="left">不合理原因</el-divider>

      <el-row>
        <el-col :span="8">
          <el-form-item label="处方不合理原因">
            <el-cascader v-model="value" :options="options" @change="handleChange" style="width: 450px;"></el-cascader>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>

      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="saveHandle">保存</el-button>
    </span>
  </el-dialog>

</template>

<script>
  import { getPrescriptionObj, addEimsOutpatientPrescriptionObj, putEimsOutpatientPrescriptionObj } from '@/api/eims/prescription'

  export default {
    data() {
      return {
        takeMedicineVisible: false,
        value: [],
        options: [
          {
            value: '不规范处方',
            label: '不规范处方',
            children: [
              {
                value: '书写格式不规范',
                label: '书写格式不规范',
              },
              {
                value: '药品配置不规范',
                label: '药品配置不规范'
              }
            ]
          },
          {
            value: '不适宜处方',
            label: '不适宜处方',
            children: [
              {
                value: '单次给药剂量不合理',
                label: '单次给药剂量不合理',
              },
              {
                value: '给药途径不合理',
                label: '给药途径不合理'
              }
            ]
          },
          {
            value: '超常处方',
            label: '超常处方'
          },
          {
            value: '其他处方',
            label: '其他处方'
          }

        ],
        dataList: [],
        visible: false,
        dataForm: {
          id: 0,
          presBillId: '',
          name: '',
          status: '',
          medicineStatus: '',
          presonName: '',
          presonId: '',
          visitTime: '',
          createTime: '',
          updateTime: '',
          createUser: '',
          modifyUser: '',
          tenantId: '',
          orgId: '',
          unitId: '',
          delFlag: ''
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          if (this.dataForm.id) {
            getPrescriptionObj(this.dataForm.id).then(response => {
              this.dataForm = response.data.data
              this.dataList = response.data.data.detailList
              console.log(response.data.data.detailList)
            })
          }
        })
      },
      handleChange(val){
        console.log(val)
      },
      saveHandle(){
          this.dataForm.unreasonable =  this.value.toString()
          this.dataForm.status = '2';
          putEimsOutpatientPrescriptionObj(this.dataForm).then(data => {
              this.$message.success('修改成功')
              this.visible = false
              this.$emit('refreshDataList')
          });
      }
    }
  }
</script>
